require("../../utils/function.js");

var e = getApp(), t = require("../../api.js");

Page({
    data: {
        typeindex: 0,
        type: [ "上班", "下班" ],
        listenWay: [ "抢单模式", "指派模式" ],
        listenWayDefault: 0,
        orderHobby: [ "全部", "实时", "预约" ],
        orderreceivingmode:[ "代驾","叫车","全部"],
        orderreceivingDefault:0,
        orderHobbyDefault: 0,
        mileageList: [ 0, 1, 2, 3, 5 ],
        progress: [ 0, 1, 2, 3 ],
        progressDefault: 0
    },
    onLoad: function(t) {
        t.uid && e.shareCouponsMessage(t.uid);
    },
    intoPageHandler: function(a) {
        var s = this, r = this.data.mileageList[a.currentTarget.dataset.scope + 1];
        e.request({
            url: t.driver.setUp,
            method: "post",
            data: {
                work_status: s.data.typeindex,
                way: a.currentTarget.dataset.way + 1,
                like: a.currentTarget.dataset.like,
                scope: r,
                order_receiving_mode:a.currentTarget.dataset.receiv + 1
            },
            success: function(t) {
                1 == t.code ? (0 == s.data.typeindex ? e.musicPlay("https://driving.4hl.cn/WeChat/resource/video/working.mp3") : e.musicPlay("https://driving.4hl.cn/WeChat/resource/video/after_work.mp3"), 
                wx.navigateBack({
                    delta: 1
                })) : wx.showToast({
                    title: t.msg,
                    duration: 1e3
                });
            }
        });
    },
    typeclink: function(e) {
        this.setData({
            typeindex: e.currentTarget.dataset.check
        });
    },
    checklistenWayHnadler: function(e) {
        console.log("设置听单方式", e.currentTarget.dataset.check), this.setData({
            listenWayDefault: e.currentTarget.dataset.check
        });
    },
    checkOrderHobbyHnadler: function(e) {
        this.setData({
            orderHobbyDefault: e.currentTarget.dataset.check
        });
    },
    // 接单模式.
    checkreceivinghnadler:function(e) {
        this.setData({
            orderreceivingDefault: e.currentTarget.dataset.check
        })
    },
    
    checkProgressHandler: function(e) {
        this.setData({
            progressDefault: e.currentTarget.dataset.check
        });
    },
    onReady: function() {},
    onShow: function() {
        this.getScorp();
    },
    getScorp: function() {
        var a = this;
        e.request({
            url: t.scopeseting.index,
            method: "post",
            data: {},
            success: function(e) {
                for (var t = [ "0" ], s = 0; s < e.data.scope.length; s++) t.push(e.data.scope[s]);
                a.setData({
                    mileageList: t,
                    scope: e.data.scope
                }), a.getUserSetUp(e.data.scope);
            }
        });
    },
    getUserSetUp: function(a) {
        var s = this, r = a;
        e.request({
            url: t.driver.getset,
            method: "post",
            data: {},
            success: function(e) {
                console.log(e);
                for (var t = 0, a = 0; a < r.length; a++) r[a] == e.data.scope && (t = a);
                s.setData({
                    listenWayDefault: e.data.way - 1,
                    orderHobbyDefault: e.data.like,
                    progressDefault: t,
                    typeindex: e.data.work_status,
                    orderreceivingDefault:e.data.order_receiving_mode - 1
                });
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: e.shareAppMessage().title,
            imageUrl: e.shareAppMessage().imageUrl,
            desc: e.shareAppMessage().desc,
            path: e.shareAppMessage().path
        };
    }
});